package com.carserver.controller;

import com.carserver.common.Result;
import com.carserver.pojo.Order_detail;
import com.carserver.service.Order_detailDao;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/order_detail")
public class Order_detailController {
    @Resource
    Order_detailDao dao;

    @GetMapping("/by_orderId/{orderId}")
    public Result getOrderDetailByOrderId(@PathVariable String orderId){
        List<Order_detail> l=dao.findOrder_detailByOrderId(orderId);
        return Result.success(l);
    }

    @GetMapping("/by_userId/{userId}")
    public Result getOrderDetailByUserId(@PathVariable String userId){
        List<Order_detail> l=dao.findOrder_detailByUser_id(userId);
        return Result.success(l);
    }

    @PostMapping("/save")
    public Result saveOrderDetail(@RequestBody Order_detail order_detail){
        dao.save(order_detail);
        return Result.success();
    }
    @GetMapping("/{id}/{have_number}")
    public  Result change_have_number(@PathVariable Integer id,@PathVariable Integer have_number){
        Order_detail a =dao.getOne(id);
        a.setHave_number(have_number);
        dao.save(a);
        return  Result.success();
    }


}
